<template>
	<view>
		<!-- 地图 -->
		<view class="mapBox">
			<amap-choose :color="color" :keyMap="keyMap" :AMapKeyWeb="AMapKeyWeb" :show="show" :initLocation="initLocation"
				@placeChoose="placeChoose" @changeShow="changeShow"></amap-choose>
			
			{{ address }}
		</view>
	</view>
</template>

<script>
	import amapChoose from '@/components/amap-choose/amap-choose.vue'
	export default {
		components: {
			amapChoose
		},
		data() {
			return {
				color: '#ff6000',
				keyMap: '116cb5010cc5b2bc95802fbd1b0e09a2', // webjs的key
				AMapKeyWeb: '1d1af59d351dfe3a002f0d9dd1ded50d', // web服务的key
				show: true,
				initLocation: '113.691356,34.793780', // 初始经纬度，获取当前位置后可赋值经纬度
				address: ''
			}
		},
		onLoad() {
			if (uni.getStorageSync('address')) {
				this.address = uni.getStorageSync('address')
				this.initLocation = uni.getStorageSync('longitude') + ',' + uni.getStorageSync('latitude')
			} else {
				this.initLocation = '113.691356,34.793780'
			}
		},
		methods: {
			placeChoose(val) {
				console.log('===>',val)
				this.address = val.address
				this.show = false
				uni.setStorageSync('address', val.address)
				uni.setStorageSync('latitude', val.latitude)
				uni.setStorageSync('longitude', val.longitude)
				uni.navigateBack()
			},
			changeShow(val) {
				console.log(val)
				this.address = val.address
				this.show = false
				uni.setStorageSync('address', val.address)
				uni.setStorageSync('latitude', val.latitude)
				uni.setStorageSync('longitude', val.longitude)
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="less">
page {
    background: #ffffff;
}
</style>